﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using ExtendPropertyLib.WPF;
using ExtendPropertyLib;
using ExORMDesginer.RadWindow.Helper;
using System.Threading.Tasks;

namespace ExORMDesginer.UserControls.Dialogs
{
    public class EntityInfomationDialogViewModel : ViewModelBase<EntityInfomationDialogInfo>
    {
        public async override void OnDoCreate(ExtendObject item, params object[] args)
        {
            base.OnDoCreate(item, args);
            //窗口被打开时保存Model当前状态
          
           
            
        }

        public override string GetViewTitle()
        {
            return Model.Info.Name + "设计";
        }


        public  async override void OnLoad()
        {
            await TaskEx.Run(async() =>
            {
                Model.OnLoad();
                await TaskEx.Delay(1000);
                Model.EntityInfo.BeginEdit();
            });
          
        
        }


        /// <summary>
        /// 保存
        /// </summary>
        public async void OK()
        {
            await TaskEx.Run(async() =>
            {
              Model.EndEdit();
              Model.Save();
            });
            this.TryOK();
        }

        /// <summary>
        /// 取消，回滚Model状态
        /// </summary>
        public async void Cancel()
        {

            await TaskEx.Run(async() =>
            {
                Model.EntityInfo.CancelEdit();
                Model.EntityInfo.EndEdit();
            });
        
            this.TryCancel();
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        public async override void Closed()
        {
            await TaskEx.Run(async() =>
            {
                Model.CancelEdit();
                Model.EndEdit();
            });
        }
    }
}
